#!/bin/bash
import math
import sys

import numpy as np


def read_util_ok():
    while input() != "OK":
        pass


def finish():
    sys.stdout.write('OK\n')
    sys.stdout.flush()


def distance(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)


def calculate_time_to_reach_target(x_speed, y_speed, distance):
    """
    给定物体的水平和垂直速度以及目标的距离，计算物体到达目标所需的时间
    :param x_speed: 物体在水平方向上的速度（米/秒）
    :param y_speed: 物体在垂直方向上的速度（米/秒）
    :param distance: 物体与目标之间的距离（米）
    :return: 物体到达目标所需的时间（秒）
    """
    # 计算物体在水平方向上移动的时间
    x_time = distance / x_speed
    # 计算物体在垂直方向上移动的时间
    y_time = distance / y_speed
    # 物体到达目标所需的总时间是水平和垂直移动时间之和
    total_time = x_time + y_time
    # 返回物体到达目标所需的时间
    return total_time


# 计算机器人和工作台的最短距离
def sort_bot_station(bot_location, station_location_list):
    distances = [(i, distance(bot_location, station_location)) for i, station_location in
                 enumerate(station_location_list)]
    distances.sort(key=lambda x: x[1])
    return distances


# 返回列表中相同元素的下标，大于1个才返回
def find_duplicate_indices(lst):
    d = {}
    for i, x in enumerate(lst):
        if x in d:
            d[x].append(i)
        else:
            d[x] = [i]
    return {x: idx for x, idx in d.items() if len(idx) > 1}


# 两向量夹角
def angle_between_vectors(v1, v2):
    dot_product = v1[0] * v2[0] + v1[1] * v2[1]
    v1_norm = math.sqrt(v1[0] ** 2 + v1[1] ** 2)
    v2_norm = math.sqrt(v2[0] ** 2 + v2[1] ** 2)
    cos_theta = dot_product / (v1_norm * v2_norm)
    return math.acos(cos_theta)


# 计算工作台在机器人的方位角
def calculate_angle(bot_location, station_location):
    dx = station_location[0] - bot_location[0]
    dy = station_location[1] - bot_location[1]
    theta = math.atan2(dy, dx)
    return theta


# 计算工作台原材料格状态
def find_position_of_ones(decimal_num):
    # 将十进制数转换为二进制数，并反转二进制字符串
    binary_str = bin(decimal_num)[2:][::-1]

    # 创建一个空列表来存储所有1的位置
    positions = []

    # 遍历二进制字符串，查找所有1的位置
    for i in range(len(binary_str)):
        # 如果当前位为1，则将它的位置添加到位置列表中
        if int(binary_str[i]) & 1 == 1:
            positions.append(i)

    # 返回位置列表
    return positions


# 设置线速度
def set_line_speed(station_distance):
    # return 6
    line_speed = 6
    if station_distance >= 10:
        line_speed = 6
    elif station_distance >= 8:
        line_speed = 6
    elif station_distance >= 6:
        line_speed = 6
    elif station_distance >= 2:
        line_speed = 6
    elif station_distance >= 1:
        line_speed = 5
    elif station_distance >= 0:
        line_speed = 2
    return line_speed


def calculate_speed(angular_speed):
    # 角速度转换为弧度制
    angular_speed = angular_speed / 180 * math.pi

    if abs(angular_speed) < 0.2:
        # 机器人直行时的线速度
        return 6

    elif math.pi * 3/4 > abs(angular_speed) > 0.2:
        # 机器人顺时针转动时的线速度和旋转半径
        radius = 1 / math.sin(angular_speed / 2)
        linear_speed = radius * angular_speed

        if linear_speed > 6:
            # 限制机器人线速度不超过6m/s
            linear_speed = 6

        return linear_speed

    else:
        # 机器人逆时针转动时的线速度和旋转半径
        radius = 1 / math.sin(abs(angular_speed) / 2)
        linear_speed = radius * abs(angular_speed) * 2

        if linear_speed > 2:
            # 限制机器人后退线速度不超过2m/s
            linear_speed = 2

        return -linear_speed


# 设置角速度
def set_angle_speed(bot_location, station_location, bot_direction):
    alpha = calculate_angle(bot_location, station_location)
    k = 50
    theta = alpha - bot_direction
    theta = math.atan2(math.sin(theta), math.cos(theta))
    return k * theta


# 机器人避障算法
class Robot:
    def __init__(self, x, y, angle, vx, vy, radius):
        self.x = x
        self.y = y
        self.angle = angle
        self.vx = vx
        self.vy = vy
        self.radius = radius

# 判断两条路径是否会重合
class LineSegment:
    def __init__(self, start, end):
        self.start = start
        self.end = end

    def intersects(self, other):
        # 计算两条线段的四个端点
        p1, q1 = self.start, self.end
        p2, q2 = other.start, other.end

        # 计算两条线段的方向向量和垂直向量
        v1, v2 = q1 - p1, q2 - p2
        u1, u2 = np.array([-v1[1], v1[0]]), np.array([-v2[1], v2[0]])

        # 计算两条线段在垂直方向上的投影长度
        d1 = np.dot(u1, p2 - p1)
        d2 = np.dot(u1, q2 - p1)
        d3 = np.dot(u2, p1 - p2)
        d4 = np.dot(u2, q1 - p2)

        # 如果两条线段的投影有重叠，则说明它们相交
        if d1 * d2 < 0 and d3 * d4 < 0:
            return True
        elif d1 == 0 and self._on_segment(p2):
            return True
        elif d2 == 0 and self._on_segment(q2):
            return True
        elif d3 == 0 and other._on_segment(p1):
            return True
        elif d4 == 0 and other._on_segment(q1):
            return True
        else:
            return False

    def _on_segment(self, point):
        # 检查一个点是否在当前线段上
        return (min(self.start[0], self.end[0]) <= point[0] <= max(self.start[0], self.end[0])
                and min(self.start[1], self.end[1]) <= point[1] <= max(self.start[1], self.end[1]))

# 判断两个机器人路径是否会重合
def check_path(robot1, robot2):
    """
    检查机器人之间的路径是否有重叠。
    """
    # 计算第一个机器人的位置
    r1_pos_x = robot1.x + robot1.vx * 0.02 * 15
    r1_pos_y = robot1.y + robot1.vy * 0.02 * 15

    # 计算第二个机器人的位置
    r2_pos_x = robot2.x + robot2.vx * 0.02 * 15
    r2_pos_y = robot2.y + robot2.vy * 0.02 * 15
    # 获取机器人的当前位置和目标位置
    robot1_start_position = np.array([robot1.x, robot1.y])
    robot1_end_position = np.array([r1_pos_x, r1_pos_y])

    # 获取其他机器人的当前位置和目标位置
    robot2_start_position = np.array([robot2.x, robot2.y])
    robot2_end_position = np.array([r2_pos_x, r2_pos_y])

    # 检查机器人之间的路径是否有重叠
    path1 = LineSegment(robot1_start_position, robot1_end_position)
    path2 = LineSegment(robot2_start_position, robot2_end_position)
    intersection = path1.intersects(path2)

    return intersection

# 判断两个机器人是否会碰撞
def check_collision(robot1, robot2):
    # 计算第一个机器人的位置
    r1_pos_x = robot1.x + robot1.vx * 0.02 * 15
    r1_pos_y = robot1.y + robot1.vy * 0.02 * 15

    # 计算第二个机器人的位置
    r2_pos_x = robot2.x + robot2.vx * 0.02 * 15
    r2_pos_y = robot2.y + robot2.vy * 0.02 * 15

    # 计算两个机器人之间的距离
    distance = math.sqrt((r2_pos_x - r1_pos_x) ** 2 + (r2_pos_y - r1_pos_y) ** 2)
    center_distance = math.sqrt((robot2.x - robot1.x) ** 2 + (robot2.y - robot1.y) ** 2)

    # 判断两个机器人是否会相撞
    if distance <= robot1.radius + robot2.radius:
        f.write('即将相撞\n')
        return True
    elif center_distance <= robot1.radius + robot2.radius:
        f.write('已经碰撞\n')
        return True
    else:
        return False

# 避免碰撞
def avoid_collision(i, j, robot1, robot2):
    """
    避免机器人之间的碰撞。
    """
    f.write('机器人朝向：%s，%s\n' % (str(robot1.angle), str(robot2.angle)))
    if (-math.pi < robot1.angle < -math.pi / 2 and 0 < robot2.angle < math.pi / 2) or \
            (-math.pi / 2 < robot1.angle < 0 and math.pi / 2 < robot2.angle < math.pi) or \
            (-math.pi < robot2.angle < -math.pi / 2 and 0 < robot1.angle < math.pi / 2) or \
            (-math.pi / 2 < robot2.angle < 0 and math.pi / 2 < robot1.angle < math.pi):
        f.write('情况1\n')
        angle_speed_i = -math.pi / 2 * 50
        angle_speed_j = -math.pi / 2 * 50
        line_speed_i = calculate_speed(angle_speed_i)
        line_speed_j = calculate_speed(angle_speed_j)
        sys.stdout.write('rotate %d %f\n' % (i, angle_speed_i))
        sys.stdout.write('rotate %d %f\n' % (j, angle_speed_j))
        sys.stdout.write('forward %d %d\n' % (i, 6))
        sys.stdout.write('forward %d %d\n' % (i, 6))
    # 都逆时针的情况
    elif (-math.pi / 2 < robot1.angle < 0 and math.pi / 2 < robot2.angle < math.pi) or \
            (0 < robot1.angle < math.pi / 2 and -math.pi < robot2.angle < -math.pi / 2) or \
            (-math.pi / 2 < robot2.angle < 0 and math.pi / 2 < robot1.angle < math.pi) or \
            (0 < robot2.angle < math.pi / 2 and -math.pi < robot1.angle < -math.pi / 2):
        f.write('情况2\n')
        angle_speed_i = -math.pi / 2 * 50
        angle_speed_j = -math.pi / 2 * 50
        line_speed_i = calculate_speed(angle_speed_i)
        line_speed_j = calculate_speed(angle_speed_j)
        sys.stdout.write('rotate %d %f\n' % (i, angle_speed_i))
        sys.stdout.write('rotate %d %f\n' % (j, angle_speed_j))
        sys.stdout.write('forward %d %d\n' % (i, 6))
        sys.stdout.write('forward %d %d\n' % (i, 6))
    elif (-math.pi / 2 < robot1.angle < 0 and 0 < robot2.angle < math.pi / 2) or \
            (0 < robot1.angle < math.pi / 2 < robot2.angle < math.pi) or \
            (-math.pi / 2 < robot2.angle < 0 and 0 < robot1.angle < math.pi / 2) or \
            (0 < robot2.angle < math.pi / 2 < robot1.angle < math.pi):
        f.write('情况3\n')
        angle_speed_i = -math.pi / 2 * 50
        angle_speed_j = -math.pi / 2 * 50
        line_speed_i = calculate_speed(angle_speed_i)
        line_speed_j = calculate_speed(angle_speed_j)
        sys.stdout.write('rotate %d %f\n' % (i, angle_speed_i))
        sys.stdout.write('rotate %d %f\n' % (j, angle_speed_j))
        sys.stdout.write('forward %d %d\n' % (i, 6))
        sys.stdout.write('forward %d %d\n' % (i, 6))
    elif (-math.pi < robot1.angle < -math.pi / 2 and math.pi / 2 < robot2.angle < math.pi) or \
            (0 > robot1.angle > -math.pi / 2 > robot2.angle > -math.pi) or \
            (-math.pi < robot2.angle < -math.pi / 2 and math.pi / 2 < robot1.angle < math.pi) or \
            (0 > robot2.angle > -math.pi / 2 > robot1.angle > -math.pi):
        f.write('情况4\n')
        angle_speed_i = -math.pi / 2 * 50
        angle_speed_j = -math.pi / 2 * 50
        line_speed_i = calculate_speed(angle_speed_i)
        line_speed_j = calculate_speed(angle_speed_j)
        sys.stdout.write('rotate %d %f\n' % (i, angle_speed_i))
        sys.stdout.write('rotate %d %f\n' % (j, angle_speed_j))
        sys.stdout.write('forward %d %d\n' % (i, 6))
        sys.stdout.write('forward %d %d\n' % (i, 6))
    else:
        f.write('其他情况\n')
        sys.stdout.write('forward %d %d\n' % (i, -2))
        # if robot1.vx > robot1.vy and robot1.vx > robot2.vx:
        #     sys.stdout.write('forward %d %d\n' % (i, -2))
        # else:
        #     sys.stdout.write('forward %d %d\n' % (j, -2))

# 机器人防碰撞主体函数
def avoid_collisions(robots, bot_location_list, station_location_list, bot_direction_list, bot_work_status):
    is_change_bot_target = [0, 0, 0, 0]
    # 使用碰撞检测和路径规划算法避免碰撞
    for i, robot1 in enumerate(robots):
        for j, robot2 in enumerate(robots):
            if i < j:
                # 如果两个机器人会相撞
                # f.write('判断机器人%d和%d是否会相撞：%s，%s\n' % (i, j, check_collision(robot1, robot2), check_path(robot1, robot2)))
                if check_collision(robot1, robot2):
                    is_change_bot_target[i] = 1
                    is_change_bot_target[j] = 1
                    # f.write('两个机器人情况：%s，%s\n' % (str([robot1.x, robot1.y, robot1.vx, robot1.vy]), str([robot2.x, robot2.y, robot2.vx, robot2.vy])))
                    avoid_collision(i, j, robot1, robot2)

        if is_change_bot_target[i] == 0:
            angle_speed = set_angle_speed(bot_location_list[i],
                                            station_location_list[bot_work_status[i]],
                                            bot_direction_list[i])
            line_speed = calculate_speed(angle_speed)
            sys.stdout.write('forward %d %d\n' % (i, line_speed))
            sys.stdout.write('rotate %d %f\n' % (i, angle_speed))


# 根据距离计算到达时间s
def arrival_time(distance):
    return distance / 6 * 50  # 一秒50帧


# 改变材料状态中的材料格
def change_bit(decimal, position):
    binary = bin(decimal)[2:]  # 转换为二进制字符串，去掉前缀 '0b'
    binary = binary.rjust(8, '0')
    binary_list = list(binary)  # 将字符串转换为列表
    binary_list[-position - 1] = '1'
    binary = ''.join(binary_list)  # 将列表转换回字符串
    return int(binary, 2)  # 将二进制字符串转换为十进制数并返回


if __name__ == '__main__':
    read_util_ok()  # 初始化读取地图，直到读取到OK，5ms时长
    finish()  # 打印标准输出，完成输入
    f = open('main.txt', 'w')
    # 保存机器人工作状态，有任务则前往工作台即可，不再做判断,保存对应的工作台id
    bot_work_status = [-1, -1, -1, -1]
    # 保存机器人预选目标ID
    bot_goods_status = [-1, -1, -1, -1]
    # 存储机器人预选物品类型
    bot_goods_type = [0, 0, 0, 0]
    # 机器人半径
    bot_radius_list = [0.45, 0.45, 0.45, 0.45]
    # 机器人目标位置
    bot_target_location = [[], [], [], []]

    while True:
        line1 = sys.stdin.readline()  # 第一行2个整数，表示回合数 金钱数
        if not line1:
            break

        line2 = sys.stdin.readline()  # 第二行1个整数，表示场上工作台数量K

        station_type_list = []  # 工作台类型列表
        station_location_list = []  # 工作台位置列表
        station_process_list = []  # 生产状态列表
        station_material_list = []  # 原材料状态
        station_production_list = []  # 产品状态
        for i in range(int(line2)):
            line_i = sys.stdin.readline()
            station_i = line_i.strip().split(' ')
            station_type_list.append(int(station_i[0]))
            station_location_list.append((float(station_i[1]), float(station_i[2])))
            station_process_list.append(int(station_i[3]))
            station_material_list.append(int(station_i[4]))
            station_production_list.append(int(station_i[5]))
            # f.write('第%d个工作台转态：' % (i + 1) + line_i)

        bot_station_list = []  # 机器人所处工作站
        bot_type_list = []  # 机器人携带物品类型
        bot_time_list = []  # 机器人时间价值系数
        bot_collision_list = []  # 机器人碰撞价值系数
        bot_angle_speed_list = []  # 机器人角速度
        bot_line_speed_list = []  # 机器人线速度
        bot_direction_list = []  # 机器人方向
        bot_location_list = []  # 机器人位置

        robots = []
        for j in range(4):
            line_j = sys.stdin.readline()
            bot_i = line_j.strip().split(' ')
            bot_station_list.append(int(bot_i[0]))
            bot_type_list.append(int(bot_i[1]))
            bot_time_list.append(float(bot_i[2]))
            bot_collision_list.append(float(bot_i[3]))
            bot_angle_speed_list.append(float(bot_i[4]))
            bot_line_speed_list.append((float(bot_i[5]), float(bot_i[6])))
            bot_direction_list.append(float(bot_i[7]))
            bot_location_list.append((float(bot_i[8]), float(bot_i[9])))
            # f.write('第%d个机器人状态：' % (j + 1) + line_j)
            if bot_type_list[j] != 0:
                robots.append(
                    Robot(float(bot_i[8]), float(bot_i[9]), float(bot_i[7]), float(bot_i[5]), float(bot_i[6]), 0.53))
            else:
                robots.append(
                    Robot(float(bot_i[8]), float(bot_i[9]), float(bot_i[7]), float(bot_i[5]), float(bot_i[6]), 0.45))
        read_util_ok()  # 读取地图，直到读取到OK

        # 地图读取完成，开始操作
        parts = line1.split(' ')
        frame_id = int(parts[0])
        sys.stdout.write('%d\n' % frame_id)  # 第一行需要输出一个整数，表示帧ID
        f.write('回合数：' + str(frame_id) + '\n')
        f.write('金钱数：' + str(parts[1]))
        for i in range(len(bot_work_status)):
            if bot_work_status[i] != -1 and bot_goods_status[i] != -1 and bot_goods_type[i] not in [7, 8, 9]:
                # f.write(str('更新材料列表'))
                station_material_list[bot_goods_status[i]] = change_bit(station_material_list[bot_goods_status[i]], bot_goods_type[i])
        for robot_id in range(4):
            f.write('第%d辆小车\n' % (robot_id + 1))
            f.write('机器人目标：%s，携带物品：%s，预定目标：%s，预定物品：%s\n' % (str(bot_work_status), str(bot_type_list), str(bot_goods_status), str(bot_goods_type)))
            # 机器人在工作台附近
            if bot_station_list[robot_id] != -1 and bot_station_list[robot_id] == bot_work_status[robot_id]:

                # 位于1/2/3工作台附近,只考虑购买
                if station_type_list[bot_station_list[robot_id]] in [1, 2, 3]:
                    f.write('触发1\n')
                    target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                    # 没有物品，且目标为4/5/6，且有产品
                    if bot_type_list[robot_id] == 0 and station_type_list[bot_goods_status[robot_id]] in [4, 5, 6]:
                        if station_production_list[bot_station_list[robot_id]] == 1 and (9000 - frame_id) > target_distance / 4 * 50:
                            sys.stdout.write('buy %d\n' % robot_id)
                            bot_type_list[robot_id] = station_type_list[bot_station_list[robot_id]]
                            bot_work_status[robot_id] = bot_goods_status[robot_id]

                # 如果工作台在4/5/6附近
                elif station_type_list[bot_station_list[robot_id]] in [4, 5, 6]:
                    f.write('触发2\n')
                    target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                    # 如果机器人无物品，且目标为7/9
                    if bot_type_list[robot_id] == 0 and station_type_list[bot_goods_status[robot_id]] in [7, 9] and bot_work_status[robot_id] == bot_station_list[robot_id]:
                        f.write('触发2.1\n')
                        if station_production_list[bot_station_list[robot_id]] == 1 and (9000 - frame_id) > target_distance / 4 * 50:
                            sys.stdout.write('buy %d\n' % robot_id)
                            bot_type_list[robot_id] = station_type_list[bot_station_list[robot_id]]
                            bot_work_status[robot_id] = bot_goods_status[robot_id]
                    # 机器人有物品,目标为4/5/6
                    else:
                        f.write('触发2.2\n')
                        # 先卖物品
                        sys.stdout.write('sell %d\n' % robot_id)
                        bot_type_list[robot_id] = 0
                        bot_work_status[robot_id] = -1
                        # 如果当前工作台是预需求工作台，则重置
                        if bot_goods_status[robot_id] == bot_station_list[robot_id]:
                            bot_goods_status[robot_id] = -1
                            bot_goods_type[robot_id] = 0
                        # 判断有无7号物品,且不在其他机器人目标内
                        sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                        for station_id, station_distance in sort_station_distance:
                            if (station_production_list[station_id] == 1 or 0 < station_process_list[station_id] < arrival_time(station_id)) and \
                                    not (station_id in bot_work_status and bot_goods_type[bot_work_status.index(station_id)] == 7):
                                f.write('触发7.2\n')
                                # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间

                                bot_work_status[robot_id] = station_id
                                bot_goods_status[robot_id] = -1
                                bot_goods_type[robot_id] = 7
                                break
                        # 机器人无目标 and 无物品 and 当前工作台有产品
                        if bot_work_status[robot_id] == -1 and bot_type_list[robot_id] == 0 and station_production_list[bot_station_list[robot_id]] == 1:
                            f.write('触发2.2.1\n')
                            # 判断当前工作台产品是否已经被预定了
                            is_target = False
                            for i in range(4):
                                if bot_work_status[i] == bot_station_list[robot_id] and bot_goods_type[i] == station_type_list[bot_station_list[robot_id]]:
                                    is_target = True
                            if not is_target:
                                sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                                # 寻找差一个材料的7号工作台
                                for station_id, station_distance in sort_station_distance:
                                    material_status = find_position_of_ones(station_material_list[station_id])
                                    target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                                    if (station_type_list[bot_station_list[robot_id]] not in material_status and station_type_list[station_id] == 7) and \
                                            (9000 - frame_id) > target_distance / 4 * 50 and len(material_status) == 2:
                                            # not (bot_station_list[robot_id] in bot_work_status and bot_goods_type[bot_work_status.index(bot_station_list[robot_id])] == station_type_list[bot_station_list[robot_id]]) and \
                                            # not (bot_station_list[robot_id] in bot_goods_status and bot_goods_type[bot_goods_status.index(bot_station_list[robot_id])] == station_type_list[bot_station_list[robot_id]]):
                                        if bot_station_list[robot_id] in bot_work_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_work_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif bot_station_list[robot_id] in bot_goods_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_goods_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif bot_work_status.count(bot_station_list[robot_id]) > 2:
                                            continue
                                        f.write('触发2.2.1.1\n')
                                        sys.stdout.write('buy %d\n' % robot_id)
                                        bot_type_list[robot_id] = station_type_list[bot_station_list[robot_id]]
                                        bot_work_status[robot_id] = station_id
                                        bot_goods_status[robot_id] = station_id
                                        bot_goods_type[robot_id] = station_type_list[bot_station_list[robot_id]]
                                        station_material_list[station_id] = change_bit(station_material_list[station_id], station_type_list[bot_station_list[robot_id]])
                                        break
                                # 差两个材料的工作台
                                if bot_work_status[robot_id] == -1:
                                    for station_id, station_distance in sort_station_distance:
                                        material_status = find_position_of_ones(station_material_list[station_id])
                                        target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                                        if (station_type_list[bot_station_list[robot_id]] not in material_status and station_type_list[station_id] == 7) and \
                                                (9000 - frame_id) > target_distance / 4 * 50 and len(material_status) == 1:
                                                # not (bot_station_list[robot_id] in bot_work_status and bot_goods_type[bot_work_status.index(bot_station_list[robot_id])] == station_type_list[bot_station_list[robot_id]]) and \
                                                # not (bot_station_list[robot_id] in bot_goods_status and bot_goods_type[bot_goods_status.index(bot_station_list[robot_id])] == station_type_list[bot_station_list[robot_id]]):
                                            if bot_station_list[robot_id] in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_station_list[robot_id] in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(bot_station_list[robot_id]) > 2:
                                                continue
                                            f.write('触发2.2.1.1\n')
                                            sys.stdout.write('buy %d\n' % robot_id)
                                            bot_type_list[robot_id] = station_type_list[bot_station_list[robot_id]]
                                            bot_work_status[robot_id] = station_id
                                            bot_goods_status[robot_id] = station_id
                                            bot_goods_type[robot_id] = station_type_list[bot_station_list[robot_id]]
                                            station_material_list[station_id] = change_bit(station_material_list[station_id], station_type_list[bot_station_list[robot_id]])
                                            break
                                # 不差材料的工作台
                                if bot_work_status[robot_id] == -1:
                                    for station_id, station_distance in sort_station_distance:
                                        material_status = find_position_of_ones(station_material_list[station_id])
                                        target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                                        if (station_type_list[bot_station_list[robot_id]] not in material_status and station_type_list[station_id] == 7) and \
                                                (9000 - frame_id) > target_distance / 4 * 50:
                                            # not (bot_station_list[robot_id] in bot_work_status and bot_goods_type[bot_work_status.index(bot_station_list[robot_id])] == station_type_list[bot_station_list[robot_id]]) and \
                                            # not (bot_station_list[robot_id] in bot_goods_status and bot_goods_type[bot_goods_status.index(bot_station_list[robot_id])] == station_type_list[bot_station_list[robot_id]]):
                                            if bot_station_list[robot_id] in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_station_list[robot_id] in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(bot_station_list[robot_id]) > 2:
                                                continue
                                            f.write('触发2.2.1.1\n')
                                            sys.stdout.write('buy %d\n' % robot_id)
                                            bot_type_list[robot_id] = station_type_list[bot_station_list[robot_id]]
                                            bot_work_status[robot_id] = station_id
                                            bot_goods_status[robot_id] = station_id
                                            bot_goods_type[robot_id] = station_type_list[bot_station_list[robot_id]]
                                            station_material_list[station_id] = change_bit(station_material_list[station_id], station_type_list[bot_station_list[robot_id]])
                                            break
                                # 没有符合要求的7号工作台，给9号
                                if bot_work_status[robot_id] == -1 and 7 not in station_type_list:
                                    for station_id, station_distance in sort_station_distance:

                                        material_status = find_position_of_ones(station_material_list[station_id])
                                        target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                                        if station_type_list[station_id] == 9:
                                            f.write('触发2.2.1.2\n')
                                            sys.stdout.write('buy %d\n' % robot_id)

                                            bot_type_list[robot_id] = station_type_list[bot_station_list[robot_id]]
                                            bot_work_status[robot_id] = station_id
                                            bot_goods_status[robot_id] = station_id
                                            bot_goods_type[robot_id] = station_type_list[bot_station_list[robot_id]]
                                            # station_material_list[station_id] = change_bit(station_material_list[station_id], station_type_list[bot_station_list[robot_id]])
                                            break

                        # 机器人无目标 and 物品栏无商品 and 当前工作台无产品
                        else:
                            f.write('触发2.2.2\n')
                            sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                            if 7 in station_type_list:
                                for saven_need_id, saven_need_distance in sort_station_distance:
                                    if station_type_list[saven_need_id] != 7:
                                        continue
                                    saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                    for need_material_id, need_material_distance in sort_station_distance:
                                        if need_material_distance > 25:
                                            continue
                                        # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                        if station_type_list[need_material_id] in [4, 5, 6] and \
                                                station_type_list[need_material_id] not in saven_need_material_status and \
                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)) and \
                                                len(saven_need_material_status) > 0:

                                            if need_material_id in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif need_material_id in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(need_material_id) > 2:
                                                continue
                                            f.write('触发2.2.2.1\n')
                                            bot_work_status[robot_id] = need_material_id
                                            bot_goods_status[robot_id] = saven_need_id
                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                            station_material_list[saven_need_id] = change_bit(station_material_list[saven_need_id], station_type_list[need_material_id])
                                            break

                                    # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.2\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏有原料且不满
                                                if len(second_need_material_status) == 1:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发2.2.2.2\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(
                                                                station_material_list[second_need_id],
                                                                station_type_list[need_material_id])
                                                            break
                                                    if bot_work_status[robot_id] != -1:
                                                        break
                                        # 所有4/5/6工作台都没有生产或有部分原料
                                        if bot_work_status[robot_id] == -1:
                                            # f.write('触发9.2.3\n')
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and \
                                                        station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏无
                                                    if len(second_need_material_status) == 0:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                f.write('触发2.2.2.3\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                                break
                                                        if bot_work_status[robot_id] != -1:
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                    if bot_work_status[robot_id] != -1:
                                        break
                                # 没有7需要材料，则去看4/5/6需不需要材料
                                if bot_work_status[robot_id] == -1:
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6]:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏有原料且不满
                                            if len(second_need_material_status) == 1:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    # if need_material_distance > 25:
                                                    #     continue
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or \
                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                        if bot_work_status.count(need_material_id) > 2:
                                                            continue
                                                        f.write('触发2.2.2.4\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(
                                                            station_material_list[second_need_id],
                                                            station_type_list[need_material_id])
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break
                                    # 所有4/5/6工作台都没有生产或有部分原料
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.3\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6]:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏无
                                                if len(second_need_material_status) == 0:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                    need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发2.2.2.5\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                            # 无7工作台
                            else:
                                for saven_need_id, saven_need_distance in sort_station_distance:
                                    saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                    # f.write('触发9.2.1\n')
                                    for need_material_id, need_material_distance in sort_station_distance:
                                        if need_material_distance > 25:
                                            continue
                                        # f.write('触发9.2.1.1\n')
                                        # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                        if station_type_list[need_material_id] in [4, 5, 6] and \
                                                station_type_list[need_material_id] not in saven_need_material_status and \
                                                (station_production_list[need_material_id] == 1 or \
                                                 0 < station_process_list[need_material_id] < arrival_time(
                                                            need_material_distance)):
                                            if need_material_id in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif need_material_id in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(need_material_id) > 2:
                                                continue
                                            f.write('触发7.6\n')
                                            bot_work_status[robot_id] = need_material_id
                                            bot_goods_status[robot_id] = saven_need_id
                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                            station_material_list[saven_need_id] = change_bit(
                                                station_material_list[saven_need_id],
                                                station_type_list[need_material_id])
                                            break

                                    # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.2\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏有原料且不满
                                                if len(second_need_material_status) == 1:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or \
                                                                 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发7.7\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(
                                                                station_material_list[second_need_id],
                                                                station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                        # 所有4/5/6工作台都没有生产或有部分原料
                                        if bot_work_status[robot_id] == -1:
                                            # f.write('触发9.2.3\n')
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and \
                                                        station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏无
                                                    if len(second_need_material_status) == 0:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # if need_material_distance > 25:
                                                            #     continue
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                        need_material_distance)):
                                                                if bot_work_status.count(need_material_id) > 2:
                                                                    continue
                                                                f.write('触发7.8\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                                break
                                                if bot_work_status[robot_id] != -1:
                                                    break
                                    if bot_work_status[robot_id] != -1:
                                        break

                # 位于7号工作台
                elif station_type_list[bot_station_list[robot_id]] == 7:
                    f.write('触发3\n')
                    target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                    # 判断是否为8/9工作台需求物品
                    if bot_type_list[robot_id] == 0 and station_type_list[bot_goods_status[robot_id]] in [8, 9]:
                        f.write('触发3.1\n')
                        if station_production_list[bot_station_list[robot_id]] == 1 and (9000 - frame_id) > target_distance / 4 * 50:
                            sys.stdout.write('buy %d\n' % robot_id)
                            bot_type_list[robot_id] = 7
                            bot_work_status[robot_id] = bot_goods_status[robot_id]
                    # 不是购买目标，为售卖目标
                    else:
                        f.write('触发3.2\n')
                        sys.stdout.write('sell %d\n' % robot_id)
                        bot_type_list[robot_id] = 0
                        bot_work_status[robot_id] = -1
                        # 如果当前工作台是预需求工作台，则重置
                        if bot_goods_status[robot_id] == bot_station_list[robot_id]:
                            bot_goods_status[robot_id] = -1
                            bot_goods_type[robot_id] = 0
                        # 机器人无目标 and 无物品 and 当前工作台有产品
                        if bot_work_status[robot_id] == -1 and bot_type_list[robot_id] == 0 and station_production_list[bot_station_list[robot_id]] == 1:
                            f.write('触发3.2.1\n')
                            # 判断当前工作台产品是否已经被预定了
                            is_target = False
                            for i in range(4):
                                if bot_work_status[i] == bot_station_list[robot_id] and bot_goods_type[i] == station_type_list[bot_station_list[robot_id]]:
                                    is_target = True
                            if not is_target:
                                sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                                for station_id, station_distance in sort_station_distance:
                                    target_distance = distance(station_location_list[bot_station_list[robot_id]], station_location_list[bot_goods_status[robot_id]])
                                    if station_type_list[station_id] in [8, 9] and (9000 - frame_id) > target_distance / 4 * 50:
                                            # not (bot_station_list[robot_id] in bot_work_status and bot_goods_type[bot_work_status.index(bot_station_list[robot_id])] == 7) and \
                                            # not (bot_station_list[robot_id] in bot_goods_status and bot_goods_type[bot_goods_status.index(bot_station_list[robot_id])] == 7):
                                        if bot_station_list[robot_id] in bot_work_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_work_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif bot_station_list[robot_id] in bot_goods_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[bot_station_list[robot_id]] and bot_station_list[robot_id] == bot_goods_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif bot_work_status.count(bot_station_list[robot_id]) > 2:
                                            continue
                                        sys.stdout.write('buy %d\n' % robot_id)
                                        f.write('触发3.2.1.1\n')

                                        bot_type_list[robot_id] = station_type_list[bot_station_list[robot_id]]
                                        bot_work_status[robot_id] = station_id
                                        bot_goods_status[robot_id] = station_id
                                        bot_goods_type[robot_id] = station_type_list[bot_station_list[robot_id]]
                                        break
                        # 机器人无目标 and 物品栏无商品 and 当前工作台无产品
                        else:
                            f.write('触发3.2.2\n')
                            sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                            for saven_need_id, saven_need_distance in sort_station_distance:
                                if station_type_list[saven_need_id] != 7:
                                    continue
                                saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                # f.write('触发9.2.1\n')
                                for need_material_id, need_material_distance in sort_station_distance:
                                    if need_material_distance > 25:
                                        continue
                                    # f.write('触发9.2.1.1\n')
                                    # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                    if station_type_list[need_material_id] in [4, 5, 6] and \
                                            station_type_list[need_material_id] not in saven_need_material_status and \
                                            (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                        if need_material_id in bot_work_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif need_material_id in bot_goods_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif bot_work_status.count(need_material_id) > 2:
                                            continue
                                        f.write('触发3.2.2.1\n')
                                        bot_work_status[robot_id] = need_material_id
                                        bot_goods_status[robot_id] = saven_need_id
                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                        station_material_list[saven_need_id] = change_bit(
                                            station_material_list[saven_need_id],
                                            station_type_list[need_material_id])
                                        break

                                # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                if bot_work_status[robot_id] == -1:
                                    # f.write('触发9.2.2\n')
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏有原料且不满
                                            if len(second_need_material_status) == 1:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    # if need_material_distance > 25:
                                                    #     continue
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                        if bot_work_status.count(need_material_id) > 2:
                                                            continue
                                                        f.write('触发3.2.2.2\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(
                                                            station_material_list[second_need_id],
                                                            station_type_list[need_material_id])
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break
                                    # 所有4/5/6工作台都没有生产或有部分原料
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.3\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and \
                                                    station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏无
                                                if len(second_need_material_status) == 0:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                    need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发3.2.2.3\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                            break
                                                    if bot_work_status[robot_id] != -1:
                                                        break
                                if bot_work_status[robot_id] != -1:
                                    break

                            # 没有7需要材料，则去看4/5/6需不需要材料
                            if bot_work_status[robot_id] == -1:
                                for second_need_id, second_need_distance in sort_station_distance:
                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                    if station_type_list[second_need_id] in [4, 5, 6]:
                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                        # 材料栏有原料且不满
                                        if len(second_need_material_status) == 1:
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                # if need_material_distance > 25:
                                                #     continue
                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or \
                                                         0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                    if bot_work_status.count(need_material_id) > 2:
                                                        continue
                                                    f.write('触发3.2.2.4\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = second_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[second_need_id] = change_bit(
                                                        station_material_list[second_need_id],
                                                        station_type_list[need_material_id])
                                                    break
                                    if bot_work_status[robot_id] != -1:
                                        break
                                # 所有4/5/6工作台都没有生产或有部分原料
                                if bot_work_status[robot_id] == -1:
                                    # f.write('触发9.2.3\n')
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6]:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏无
                                            if len(second_need_material_status) == 0:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    # if need_material_distance > 25:
                                                    #     continue
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                need_material_distance)):
                                                        if bot_work_status.count(need_material_id) > 2:
                                                            continue
                                                        f.write('触发3.2.2.5\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break



                elif station_type_list[bot_station_list[robot_id]] == 8:
                    if bot_type_list[robot_id] == 7:
                        f.write('触发4\n')
                        sys.stdout.write('sell %d\n' % robot_id)
                        bot_type_list[robot_id] = 0
                        bot_work_status[robot_id] = -1
                        if bot_goods_status[robot_id] == bot_station_list[robot_id]:
                            bot_goods_status[robot_id] = -1
                            bot_goods_type[robot_id] = 0
                        if bot_work_status[robot_id] == -1 and bot_type_list[robot_id] == 0:
                            # 判断有无7号物品,且不在其他机器人目标内
                            sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                            for station_id, station_distance in sort_station_distance:
                                if (station_production_list[station_id] == 1 or 0 < station_process_list[station_id] < arrival_time(station_id)) and \
                                        not (station_id in bot_work_status and bot_goods_type[bot_work_status.index(station_id)] == 7):
                                    f.write('触发7.2\n')
                                    # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间

                                    bot_work_status[robot_id] = station_id
                                    bot_goods_status[robot_id] = -1
                                    bot_goods_type[robot_id] = 7
                                    break
                            if 7 in station_type_list and bot_work_status[robot_id] == -1:
                                # todo 循环找到7号工作台且有材料在原料栏但差一样材料的
                                for saven_need_id, saven_need_distance in sort_station_distance:
                                    # if saven_need_distance > 25:
                                    #     continue
                                    if station_type_list[saven_need_id] == 7:
                                        saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                        # 判断有无7号物品,且不在其他机器人目标内
                                        # if (station_production_list[saven_need_id] == 1 or 0 < station_process_list[saven_need_id] < arrival_time(saven_need_distance)) and \
                                        #         not (saven_need_id in bot_work_status and bot_goods_type[bot_work_status.index(saven_need_id)] == 7):
                                        #     f.write('触发7.2\n')
                                        #     # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间
                                        #
                                        #     bot_work_status[robot_id] = saven_need_id
                                        #     bot_goods_status[robot_id] = -1
                                        #     bot_goods_type[robot_id] = 7
                                        #     break
                                        # 材料栏有原料且不满
                                        if len(saven_need_material_status) == 2:
                                            # f.write('触发9.1.2\n')
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                if need_material_distance > 25:
                                                    continue
                                                # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间,且不在目标内
                                                if station_type_list[need_material_id] in [4, 5, 6] and station_type_list[need_material_id] not in saven_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                                    if need_material_id in bot_work_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif need_material_id in bot_goods_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif bot_work_status.count(need_material_id) > 2:
                                                        continue
                                                    f.write('触发7.3\n')
                                                    # f.write('触发9.1.3\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = saven_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[saven_need_id] = change_bit(
                                                        station_material_list[saven_need_id],
                                                        station_type_list[need_material_id])
                                                    break

                                            # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                            if bot_work_status[robot_id] == -1:
                                                for second_need_id, second_need_distance in sort_station_distance:
                                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                    if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                        # 材料栏有原料且不满
                                                        if len(second_need_material_status) == 1:
                                                            for need_material_id, need_material_distance in sort_station_distance:
                                                                # if need_material_distance > 25:
                                                                #     continue
                                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                                        (station_production_list[need_material_id] == 1 or \
                                                                         0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                    if bot_work_status.count(need_material_id) > 2:
                                                                        continue
                                                                    f.write('触发7.4\n')
                                                                    bot_work_status[robot_id] = need_material_id
                                                                    bot_goods_status[robot_id] = second_need_id
                                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                    station_material_list[second_need_id] = change_bit(
                                                                        station_material_list[second_need_id],
                                                                        station_type_list[need_material_id])
                                                                    break
                                                    if bot_work_status[robot_id] != -1:
                                                        break
                                                # 所有4/5/6工作台都没有生产或有部分原料
                                                if bot_work_status[robot_id] == -1:
                                                    for second_need_id, second_need_distance in sort_station_distance:
                                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                        if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                            # 材料栏有原料且不满
                                                            if len(second_need_material_status) == 0:
                                                                for need_material_id, need_material_distance in sort_station_distance:
                                                                    # if need_material_distance > 25:
                                                                    #     continue
                                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                                            (station_production_list[need_material_id] == 1 or \
                                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                        if bot_work_status.count(need_material_id) > 2:
                                                                            continue
                                                                        f.write('触发7.5\n')
                                                                        bot_work_status[robot_id] = need_material_id
                                                                        bot_goods_status[robot_id] = second_need_id
                                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                        station_material_list[second_need_id] = change_bit(
                                                                            station_material_list[second_need_id],
                                                                            station_type_list[need_material_id])
                                                                        break
                                                        if bot_work_status[robot_id] != -1:
                                                            break
                                    if bot_work_status[robot_id] != -1:
                                        break

                                # 循环找到7号工作台且有材料在原料栏但差材料的
                                for saven_need_id, saven_need_distance in sort_station_distance:
                                    if station_type_list[saven_need_id] == 7:
                                        # f.write('触发9.1.1\n')
                                        saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                        # # 判断有无7号物品,且不在其他机器人目标内
                                        # if (station_production_list[saven_need_id] == 1 or 0 < station_process_list[saven_need_id] < arrival_time(saven_need_distance)) and \
                                        #         not (saven_need_id in bot_work_status and bot_goods_type[bot_work_status.index(saven_need_id)] == 7):
                                        #     f.write('触发4.1\n')
                                        #     # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间
                                        #     bot_work_status[robot_id] = saven_need_id
                                        #     bot_goods_status[robot_id] = -1
                                        #     bot_goods_type[robot_id] = 7
                                        #     break
                                        # 材料栏有原料且不满
                                        if len(saven_need_material_status) != 0 and len(saven_need_material_status) != 3:
                                            # f.write('触发9.1.2\n')
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                if need_material_distance > 25:
                                                    continue
                                                # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                if station_type_list[need_material_id] in [4, 5, 6] and \
                                                        station_type_list[need_material_id] not in saven_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or \
                                                         0 < station_process_list[need_material_id] < arrival_time(
                                                                    need_material_distance)):
                                                    if need_material_id in bot_work_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif need_material_id in bot_goods_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif bot_work_status.count(need_material_id) > 2:
                                                        continue
                                                    f.write('触发4.2\n')
                                                    # f.write('触发9.1.3\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = saven_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[saven_need_id] = change_bit(
                                                        station_material_list[saven_need_id],
                                                        station_type_list[need_material_id])
                                                    break

                                            # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                            if bot_work_status[robot_id] == -1:
                                                for second_need_id, second_need_distance in sort_station_distance:
                                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                    if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                        # 材料栏有原料且不满
                                                        if len(second_need_material_status) == 1:
                                                            for need_material_id, need_material_distance in sort_station_distance:
                                                                # if need_material_distance > 25:
                                                                #     continue
                                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                                        (station_production_list[need_material_id] == 1 or \
                                                                         0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                    if bot_work_status.count(need_material_id) > 2:
                                                                        continue
                                                                    f.write('触发4.3\n')
                                                                    bot_work_status[robot_id] = need_material_id
                                                                    bot_goods_status[robot_id] = second_need_id
                                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                    station_material_list[second_need_id] = change_bit(
                                                                        station_material_list[second_need_id],
                                                                        station_type_list[need_material_id])
                                                                    break
                                                            if bot_work_status[robot_id] != -1:
                                                                break
                                                # 所有4/5/6工作台都没有生产或有部分原料
                                                if bot_work_status[robot_id] == -1:
                                                    for second_need_id, second_need_distance in sort_station_distance:
                                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                        if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                            # 材料栏有原料且不满
                                                            if len(second_need_material_status) == 0:
                                                                for need_material_id, need_material_distance in sort_station_distance:
                                                                    # if need_material_distance > 25:
                                                                    #     continue
                                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                                            (station_production_list[need_material_id] == 1 or \
                                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                        if bot_work_status.count(need_material_id) > 2:
                                                                            continue
                                                                        f.write('触发4.4\n')
                                                                        bot_work_status[robot_id] = need_material_id
                                                                        bot_goods_status[robot_id] = second_need_id
                                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                        station_material_list[second_need_id] = change_bit(
                                                                            station_material_list[second_need_id],
                                                                            station_type_list[need_material_id])
                                                                        break
                                                                if bot_work_status[robot_id] != -1:
                                                                    break
                                    if bot_work_status[robot_id] != -1:
                                        break
                                # 不差材料的情况下
                                if bot_work_status[robot_id] == -1:
                                    f.write('触发4.5\n')
                                    for saven_need_id, saven_need_distance in sort_station_distance:
                                        if station_type_list[saven_need_id] != 7:
                                            continue
                                        saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                        # f.write('触发9.2.1\n')
                                        for need_material_id, need_material_distance in sort_station_distance:
                                            if need_material_distance > 25:
                                                continue
                                            # f.write('触发9.2.1.1\n')
                                            # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                            if station_type_list[need_material_id] in [4, 5, 6] and \
                                                    station_type_list[need_material_id] not in saven_need_material_status and \
                                                    (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                                if need_material_id in bot_work_status:
                                                    is_repeat = False
                                                    for i in range(4):
                                                        if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                            is_repeat = True
                                                            break
                                                    if is_repeat:
                                                        continue
                                                elif need_material_id in bot_goods_status:
                                                    is_repeat = False
                                                    for i in range(4):
                                                        if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                            is_repeat = True
                                                            break
                                                    if is_repeat:
                                                        continue
                                                elif bot_work_status.count(need_material_id) > 2:
                                                    continue
                                                bot_work_status[robot_id] = need_material_id
                                                bot_goods_status[robot_id] = saven_need_id
                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                station_material_list[saven_need_id] = change_bit(
                                                    station_material_list[saven_need_id],
                                                    station_type_list[need_material_id])
                                                break

                                        # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                        if bot_work_status[robot_id] == -1:
                                            # f.write('触发9.2.2\n')
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏有原料且不满
                                                    if len(second_need_material_status) == 1:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # if need_material_distance > 25:
                                                            #     continue
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                if bot_work_status.count(need_material_id) > 2:
                                                                    continue
                                                                f.write('触发4.6\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(
                                                                    station_material_list[second_need_id],
                                                                    station_type_list[need_material_id])
                                                                break
                                                        if bot_work_status[robot_id] != -1:
                                                            break
                                            # 所有4/5/6工作台都没有生产或有部分原料
                                            if bot_work_status[robot_id] == -1:
                                                # f.write('触发9.2.3\n')
                                                for second_need_id, second_need_distance in sort_station_distance:
                                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                    if station_type_list[second_need_id] in [4, 5, 6] and \
                                                            station_type_list[second_need_id] not in saven_need_material_status:
                                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                        # 材料栏无
                                                        if len(second_need_material_status) == 0:
                                                            for need_material_id, need_material_distance in sort_station_distance:
                                                                # if need_material_distance > 25:
                                                                #     continue
                                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                                        (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                            need_material_distance)):
                                                                    if bot_work_status.count(need_material_id) > 2:
                                                                        continue
                                                                    f.write('触发4.7\n')
                                                                    bot_work_status[robot_id] = need_material_id
                                                                    bot_goods_status[robot_id] = second_need_id
                                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                    station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                                    break
                                                            if bot_work_status[robot_id] != -1:
                                                                break
                                                if bot_work_status[robot_id] != -1:
                                                    break


                                # 没有7需要材料，则去看4/5/6需不需要材料
                                if bot_work_status[robot_id] == -1:
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6]:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏有原料且不满
                                            if len(second_need_material_status) == 1:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    # if need_material_distance > 25:
                                                    #     continue
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or \
                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                        if bot_work_status.count(need_material_id) > 2:
                                                            continue
                                                        f.write('触发4.7\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(
                                                            station_material_list[second_need_id],
                                                            station_type_list[need_material_id])
                                                        break
                                                if bot_work_status[robot_id] != -1:
                                                    break
                                    # 所有4/5/6工作台都没有生产或有部分原料
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.3\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6]:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏无
                                                if len(second_need_material_status) == 0:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                    need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发4.8\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                            break
                                                    if bot_work_status[robot_id] != -1:
                                                        break


                elif station_type_list[bot_station_list[robot_id]] == 9:
                    if bot_type_list[robot_id] in [1, 2, 3, 4, 5, 6, 7]:
                        f.write('触发5\n')
                        sys.stdout.write('sell %d\n' % robot_id)
                        bot_type_list[robot_id] = 0
                        bot_work_status[robot_id] = -1
                        bot_goods_status[robot_id] = -1
                        bot_goods_type[robot_id] = 0
                        if bot_work_status[robot_id] == -1 and bot_type_list[robot_id] == 0:
                            # 判断有无7号物品,且不在其他机器人目标内
                            sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                            for station_id, station_distance in sort_station_distance:
                                if (station_production_list[station_id] == 1 or 0 < station_process_list[station_id] < arrival_time(station_id)) and \
                                        not (station_id in bot_work_status and bot_goods_type[bot_work_status.index(station_id)] == 7):
                                    f.write('触发7.2\n')
                                    # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间

                                    bot_work_status[robot_id] = station_id
                                    bot_goods_status[robot_id] = -1
                                    bot_goods_type[robot_id] = 7
                                    break
                            if 7 in station_type_list and bot_work_status[robot_id] == -1:
                                f.write('触发5.1\n')
                                # todo 循环找到7号工作台且有材料在原料栏但差一样材料的
                                for saven_need_id, saven_need_distance in sort_station_distance:
                                    # if saven_need_distance > 25:
                                    #     continue
                                    if station_type_list[saven_need_id] == 7:
                                        saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                        # # 判断有无7号物品,且不在其他机器人目标内
                                        # if (station_production_list[saven_need_id] == 1 or 0 < station_process_list[saven_need_id] < arrival_time(saven_need_distance)) and \
                                        #         not (saven_need_id in bot_work_status and bot_goods_type[bot_work_status.index(saven_need_id)] == 7):
                                        #     f.write('触发7.2\n')
                                        #     # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间
                                        #
                                        #     bot_work_status[robot_id] = saven_need_id
                                        #     bot_goods_status[robot_id] = -1
                                        #     bot_goods_type[robot_id] = 7
                                        #     break
                                        # 材料栏有原料且不满
                                        if len(saven_need_material_status) == 2:
                                            # f.write('触发9.1.2\n')
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                if need_material_distance > 25:
                                                    continue
                                                # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间,且不在目标内
                                                if station_type_list[need_material_id] in [4, 5, 6] and station_type_list[need_material_id] not in saven_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                                    if need_material_id in bot_work_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif need_material_id in bot_goods_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif bot_work_status.count(need_material_id) > 2:
                                                        continue
                                                    f.write('触发7.3\n')
                                                    # f.write('触发9.1.3\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = saven_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[saven_need_id] = change_bit(
                                                        station_material_list[saven_need_id],
                                                        station_type_list[need_material_id])
                                                    break

                                            # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                            if bot_work_status[robot_id] == -1:
                                                for second_need_id, second_need_distance in sort_station_distance:
                                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                    if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                        # 材料栏有原料且不满
                                                        if len(second_need_material_status) == 1:
                                                            for need_material_id, need_material_distance in sort_station_distance:
                                                                # if need_material_distance > 25:
                                                                #     continue
                                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                                        (station_production_list[need_material_id] == 1 or \
                                                                         0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                    if bot_work_status.count(need_material_id) > 2:
                                                                        continue
                                                                    f.write('触发7.4\n')
                                                                    bot_work_status[robot_id] = need_material_id
                                                                    bot_goods_status[robot_id] = second_need_id
                                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                    station_material_list[second_need_id] = change_bit(
                                                                        station_material_list[second_need_id],
                                                                        station_type_list[need_material_id])
                                                                    break
                                                    if bot_work_status[robot_id] != -1:
                                                        break
                                                # 所有4/5/6工作台都没有生产或有部分原料
                                                if bot_work_status[robot_id] == -1:
                                                    for second_need_id, second_need_distance in sort_station_distance:
                                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                        if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                            # 材料栏有原料且不满
                                                            if len(second_need_material_status) == 0:
                                                                for need_material_id, need_material_distance in sort_station_distance:
                                                                    # if need_material_distance > 25:
                                                                    #     continue
                                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                                            (station_production_list[need_material_id] == 1 or \
                                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                        if bot_work_status.count(need_material_id) > 2:
                                                                            continue
                                                                        f.write('触发7.5\n')
                                                                        bot_work_status[robot_id] = need_material_id
                                                                        bot_goods_status[robot_id] = second_need_id
                                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                        station_material_list[second_need_id] = change_bit(
                                                                            station_material_list[second_need_id],
                                                                            station_type_list[need_material_id])
                                                                        break
                                                        if bot_work_status[robot_id] != -1:
                                                            break
                                    if bot_work_status[robot_id] != -1:
                                        break

                                # 循环找到7号工作台且有材料在原料栏但差材料的
                                for saven_need_id, saven_need_distance in sort_station_distance:
                                    if station_type_list[saven_need_id] == 7:
                                        # f.write('触发9.1.1\n')
                                        saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                        # # 判断有无7号物品,且不在其他机器人目标内
                                        # if (station_production_list[saven_need_id] == 1 or 0 < station_process_list[saven_need_id] < arrival_time(saven_need_distance)) and \
                                        #         not (saven_need_id in bot_work_status and bot_goods_type[bot_work_status.index(saven_need_id)] == 7):
                                        #     f.write('触发5.2\n')
                                        #     # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间
                                        #     bot_work_status[robot_id] = saven_need_id
                                        #     bot_goods_status[robot_id] = -1
                                        #     bot_goods_type[robot_id] = 7
                                        #     break
                                        # 材料栏有原料且不满
                                        if len(saven_need_material_status) != 0 and len(saven_need_material_status) != 3:
                                            # f.write('触发9.1.2\n')
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                if need_material_distance > 25:
                                                    continue
                                                # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                if station_type_list[need_material_id] in [4, 5, 6] and \
                                                        station_type_list[need_material_id] not in saven_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or \
                                                         0 < station_process_list[need_material_id] < arrival_time(
                                                                    need_material_distance)):

                                                    if need_material_id in bot_work_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif need_material_id in bot_goods_status:
                                                        is_repeat = False
                                                        for i in range(4):
                                                            if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                                is_repeat = True
                                                                break
                                                        if is_repeat:
                                                            continue
                                                    elif bot_work_status.count(need_material_id) > 2:
                                                        continue
                                                    f.write('触发5.3\n')
                                                    # f.write('触发9.1.3\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = saven_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[saven_need_id] = change_bit(
                                                        station_material_list[saven_need_id],
                                                        station_type_list[need_material_id])
                                                    break

                                            # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                            if bot_work_status[robot_id] == -1:
                                                for second_need_id, second_need_distance in sort_station_distance:
                                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                    if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                        # 材料栏有原料且不满
                                                        if len(second_need_material_status) == 1:
                                                            for need_material_id, need_material_distance in sort_station_distance:
                                                                # if need_material_distance > 25:
                                                                #     continue
                                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                                        (station_production_list[need_material_id] == 1 or \
                                                                         0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                    if bot_work_status.count(need_material_id) > 2:
                                                                        continue
                                                                    f.write('触发5.4\n')
                                                                    bot_work_status[robot_id] = need_material_id
                                                                    bot_goods_status[robot_id] = second_need_id
                                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                    station_material_list[second_need_id] = change_bit(
                                                                        station_material_list[second_need_id],
                                                                        station_type_list[need_material_id])
                                                                    break
                                                            if bot_work_status[robot_id] != -1:
                                                                break
                                                # 所有4/5/6工作台都没有生产或有部分原料
                                                if bot_work_status[robot_id] == -1:
                                                    for second_need_id, second_need_distance in sort_station_distance:
                                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                        if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                            # 材料栏有原料且不满
                                                            if len(second_need_material_status) == 0:
                                                                for need_material_id, need_material_distance in sort_station_distance:
                                                                    # if need_material_distance > 25:
                                                                    #     continue
                                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                                            (station_production_list[need_material_id] == 1 or \
                                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                        if bot_work_status.count(need_material_id) > 2:
                                                                            continue
                                                                        f.write('触发5.5\n')
                                                                        bot_work_status[robot_id] = need_material_id
                                                                        bot_goods_status[robot_id] = second_need_id
                                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                        station_material_list[second_need_id] = change_bit(
                                                                            station_material_list[second_need_id],
                                                                            station_type_list[need_material_id])
                                                                        break
                                                        if bot_work_status[robot_id] != -1:
                                                            break
                                    if bot_work_status[robot_id] != -1:
                                        break
                                # 不差材料的情况下
                                if bot_work_status[robot_id] == -1:
                                    f.write('触发5.6\n')
                                    for saven_need_id, saven_need_distance in sort_station_distance:
                                        if station_type_list[saven_need_id] != 7:
                                            continue
                                        saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                        # f.write('触发9.2.1\n')
                                        for need_material_id, need_material_distance in sort_station_distance:
                                            if need_material_distance > 25:
                                                continue
                                            # f.write('触发9.2.1.1\n')
                                            # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                            if station_type_list[need_material_id] in [4, 5, 6] and \
                                                    station_type_list[need_material_id] not in saven_need_material_status and \
                                                    (station_production_list[need_material_id] == 1 or \
                                                     0 < station_process_list[need_material_id] < arrival_time(
                                                                need_material_distance)):

                                                if need_material_id in bot_work_status:
                                                    is_repeat = False
                                                    for i in range(4):
                                                        if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                            is_repeat = True
                                                            break
                                                    if is_repeat:
                                                        continue
                                                elif need_material_id in bot_goods_status:
                                                    is_repeat = False
                                                    for i in range(4):
                                                        if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                            is_repeat = True
                                                            break
                                                    if is_repeat:
                                                        continue
                                                elif bot_work_status.count(need_material_id) > 2:
                                                    continue
                                                f.write('触发5.7\n')
                                                bot_work_status[robot_id] = need_material_id
                                                bot_goods_status[robot_id] = saven_need_id
                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                station_material_list[saven_need_id] = change_bit(
                                                    station_material_list[saven_need_id],
                                                    station_type_list[need_material_id])
                                                break

                                        # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                        if bot_work_status[robot_id] == -1:
                                            # f.write('触发9.2.2\n')
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏有原料且不满
                                                    if len(second_need_material_status) == 1:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # if need_material_distance > 25:
                                                            #     continue
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or \
                                                                     0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                if bot_work_status.count(need_material_id) > 2:
                                                                    continue
                                                                f.write('触发5.8\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(
                                                                    station_material_list[second_need_id],
                                                                    station_type_list[need_material_id])
                                                                break
                                                if bot_work_status[robot_id] != -1:
                                                    break
                                            # 所有4/5/6工作台都没有生产或有部分原料
                                            if bot_work_status[robot_id] == -1:
                                                # f.write('触发9.2.3\n')
                                                for second_need_id, second_need_distance in sort_station_distance:
                                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                    if station_type_list[second_need_id] in [4, 5, 6] and \
                                                            station_type_list[second_need_id] not in saven_need_material_status:
                                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                        # 材料栏无
                                                        if len(second_need_material_status) == 0:
                                                            for need_material_id, need_material_distance in sort_station_distance:
                                                                # if need_material_distance > 25:
                                                                #     continue
                                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                                        (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                            need_material_distance)):
                                                                    if bot_work_status.count(need_material_id) > 2:
                                                                        continue
                                                                    f.write('触发5.9\n')
                                                                    bot_work_status[robot_id] = need_material_id
                                                                    bot_goods_status[robot_id] = second_need_id
                                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                    station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                                    break
                                                    if bot_work_status[robot_id] != -1:
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break


                                # 没有7需要材料，则去看4/5/6需不需要材料
                                if bot_work_status[robot_id] == -1:
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6]:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏有原料且不满
                                            if len(second_need_material_status) == 1:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    # if need_material_distance > 25:
                                                    #     continue
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or \
                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                        if bot_work_status.count(need_material_id) > 2:
                                                            continue
                                                        f.write('触发5.10\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(
                                                            station_material_list[second_need_id],
                                                            station_type_list[need_material_id])
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break
                                    # 所有4/5/6工作台都没有生产或有部分原料
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.3\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6]:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏无
                                                if len(second_need_material_status) == 0:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                    need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发5.11\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                            # 没有7号工作台
                            else:
                                for saven_need_id, saven_need_distance in sort_station_distance:
                                    saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                    # f.write('触发9.2.1\n')
                                    for need_material_id, need_material_distance in sort_station_distance:
                                        if need_material_distance > 25:
                                            continue
                                        # f.write('触发9.2.1.1\n')
                                        # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                        if station_type_list[need_material_id] in [4, 5, 6] and \
                                                station_type_list[need_material_id] not in saven_need_material_status and \
                                                (station_production_list[need_material_id] == 1 or \
                                                 0 < station_process_list[need_material_id] < arrival_time(
                                                            need_material_distance)):

                                            if need_material_id in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif need_material_id in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(need_material_id) > 2:
                                                continue
                                            f.write('触发7.6\n')
                                            f.write('%s,%s\n' % (str(station_production_list[need_material_id] == 1),str(0 < station_process_list[need_material_id] < arrival_time(need_material_distance))))
                                            bot_work_status[robot_id] = need_material_id
                                            bot_goods_status[robot_id] = saven_need_id
                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                            station_material_list[saven_need_id] = change_bit(
                                                station_material_list[saven_need_id],
                                                station_type_list[need_material_id])
                                            break

                                    # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.2\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏有原料且不满
                                                if len(second_need_material_status) == 1:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or \
                                                                 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发7.7\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(
                                                                station_material_list[second_need_id],
                                                                station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                        # 所有4/5/6工作台都没有生产或有部分原料
                                        if bot_work_status[robot_id] == -1:
                                            # f.write('触发9.2.3\n')
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and \
                                                        station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏无
                                                    if len(second_need_material_status) == 0:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # if need_material_distance > 25:
                                                            #     continue
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(
                                                                        need_material_distance)):
                                                                if bot_work_status.count(need_material_id) > 2:
                                                                    continue
                                                                f.write('触发7.8\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                                break
                                                if bot_work_status[robot_id] != -1:
                                                    break
                                    if bot_work_status[robot_id] != -1:
                                        break

            # 机器人不在工作台附近
            else:
                if bot_work_status[robot_id] != -1:
                    f.write('触发6\n')
                    f.write('该机器人已经有目标 %d\n' % bot_work_status[robot_id])
                    station_id = bot_work_status[robot_id]
                    station_distance = distance(bot_location_list[robot_id], station_location_list[station_id])
                else:
                    f.write('触发7\n')
                    f.write('该机器人没有有目标，开始寻找 %d\n' % bot_work_status[robot_id])
                    # 判断有无7号物品,且不在其他机器人目标内
                    sort_station_distance = sort_bot_station(bot_location_list[robot_id], station_location_list)
                    for station_id, station_distance in sort_station_distance:
                        if (station_production_list[station_id] == 1 or 0 < station_process_list[station_id] < arrival_time(station_id)) and \
                                not (station_id in bot_work_status and bot_goods_type[bot_work_status.index(station_id)] == 7):
                            f.write('触发7.2\n')
                            # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间

                            bot_work_status[robot_id] = station_id
                            bot_goods_status[robot_id] = -1
                            bot_goods_type[robot_id] = 7
                            break
                    if 7 in station_type_list and bot_work_status[robot_id] == -1:
                        f.write('触发7.1\n')
                        # todo 循环找到7号工作台且有材料在原料栏但差一样材料的
                        for saven_need_id, saven_need_distance in sort_station_distance:
                            # if saven_need_distance > 25:
                            #     continue
                            if station_type_list[saven_need_id] == 7:
                                saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                # # 判断有无7号物品,且不在其他机器人目标内
                                # if (station_production_list[saven_need_id] == 1 or 0 < station_process_list[saven_need_id] < arrival_time(saven_need_distance)) and \
                                #     not (saven_need_id in bot_work_status and bot_goods_type[bot_work_status.index(saven_need_id)] == 7):
                                #     f.write('触发7.2\n')
                                #     # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间
                                #
                                #     bot_work_status[robot_id] = saven_need_id
                                #     bot_goods_status[robot_id] = -1
                                #     bot_goods_type[robot_id] = 7
                                #     break
                                # 材料栏有原料且不满
                                if len(saven_need_material_status) == 2:
                                    # f.write('触发9.1.2\n')
                                    for need_material_id, need_material_distance in sort_station_distance:
                                        if need_material_distance > 25:
                                            continue
                                        # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间,且不在目标内
                                        if station_type_list[need_material_id] in [4, 5, 6] and station_type_list[need_material_id] not in saven_need_material_status and \
                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                            if need_material_id in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif need_material_id in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(need_material_id) > 2:
                                                continue
                                            f.write('触发7.3\n')
                                            # f.write('触发9.1.3\n')
                                            bot_work_status[robot_id] = need_material_id
                                            bot_goods_status[robot_id] = saven_need_id
                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                            station_material_list[saven_need_id] = change_bit(
                                                station_material_list[saven_need_id],
                                                station_type_list[need_material_id])
                                            break

                                    # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                    if bot_work_status[robot_id] == -1:
                                        # 材料栏有原料且不满
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                if len(second_need_material_status) == 1:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or \
                                                                 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发7.4\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(
                                                                station_material_list[second_need_id],
                                                                station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                        # 所有4/5/6工作台都没有生产或有部分原料
                                        if bot_work_status[robot_id] == -1:
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏有原料且不满
                                                    if len(second_need_material_status) == 0:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # if need_material_distance > 25:
                                                            #     continue
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or \
                                                                     0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                if bot_work_status.count(need_material_id) > 2:
                                                                    continue
                                                                f.write('触发7.5\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(
                                                                    station_material_list[second_need_id],
                                                                    station_type_list[need_material_id])
                                                                break
                                                if bot_work_status[robot_id] != -1:
                                                    break
                            if bot_work_status[robot_id] != -1:
                                break
                        # 差2样材料的
                        for saven_need_id, saven_need_distance in sort_station_distance:
                            # if saven_need_distance > 25:
                            #     continue
                            if station_type_list[saven_need_id] == 7:
                                saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                # # 判断有无7号物品,且不在其他机器人目标内
                                # if (station_production_list[saven_need_id] == 1 or 0 < station_process_list[saven_need_id] < arrival_time(saven_need_distance)) and \
                                #     not (saven_need_id in bot_work_status and bot_goods_type[bot_work_status.index(saven_need_id)] == 7):
                                #     f.write('触发7.2\n')
                                #     # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间
                                #
                                #     bot_work_status[robot_id] = saven_need_id
                                #     bot_goods_status[robot_id] = -1
                                #     bot_goods_type[robot_id] = 7
                                #     break
                                # 材料栏有原料且不满
                                if len(saven_need_material_status) != 0 and len(saven_need_material_status) != 3:
                                    # f.write('触发9.1.2\n')
                                    for need_material_id, need_material_distance in sort_station_distance:
                                        if need_material_distance > 25:
                                            continue
                                        # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间,且不在目标内
                                        if station_type_list[need_material_id] in [4, 5, 6] and station_type_list[need_material_id] not in saven_need_material_status and \
                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                            if need_material_id in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif need_material_id in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(need_material_id) > 2:
                                                continue
                                            f.write('触发7.3\n')
                                            # f.write('触发9.1.3\n')
                                            bot_work_status[robot_id] = need_material_id
                                            bot_goods_status[robot_id] = saven_need_id
                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                            station_material_list[saven_need_id] = change_bit(
                                                station_material_list[saven_need_id],
                                                station_type_list[need_material_id])
                                            break

                                    # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                    if bot_work_status[robot_id] == -1:
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏有原料且不满
                                                if len(second_need_material_status) != 0 and len(second_need_material_status) != 2:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or \
                                                                 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发7.4\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(
                                                                station_material_list[second_need_id],
                                                                station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                        # 所有4/5/6工作台都没有生产或有部分原料
                                        if bot_work_status[robot_id] == -1:
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏有原料且不满
                                                    if len(second_need_material_status) == 0:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # if need_material_distance > 25:
                                                            #     continue
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or \
                                                                     0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                if bot_work_status.count(need_material_id) > 2:
                                                                    continue
                                                                f.write('触发7.5\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(
                                                                    station_material_list[second_need_id],
                                                                    station_type_list[need_material_id])
                                                                break
                                                if bot_work_status[robot_id] != -1:
                                                    break
                            if bot_work_status[robot_id] != -1:
                                break
                        # 没有原材料的情况下
                        if bot_work_status[robot_id] == -1:
                            for saven_need_id, saven_need_distance in sort_station_distance:
                                if station_type_list[saven_need_id] != 7:
                                    continue
                                saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                # f.write('触发9.2.1\n')
                                for need_material_id, need_material_distance in sort_station_distance:
                                    if need_material_distance > 25:
                                        continue
                                    # f.write('触发9.2.1.1\n')
                                    # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                    if station_type_list[need_material_id] in [4, 5, 6] and \
                                            station_type_list[need_material_id] not in saven_need_material_status and \
                                            (station_production_list[need_material_id] == 1 or \
                                             0 < station_process_list[need_material_id] < arrival_time(
                                                        need_material_distance)):

                                        if need_material_id in bot_work_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif need_material_id in bot_goods_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif bot_work_status.count(need_material_id) > 2:
                                            continue
                                        f.write('触发7.6\n')
                                        bot_work_status[robot_id] = need_material_id
                                        bot_goods_status[robot_id] = saven_need_id
                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                        station_material_list[saven_need_id] = change_bit(
                                            station_material_list[saven_need_id],
                                            station_type_list[need_material_id])
                                        break

                                # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                if bot_work_status[robot_id] == -1:
                                    # f.write('触发9.2.2\n')
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏有原料且不满
                                            if len(second_need_material_status) != 0 and len(second_need_material_status) != 2:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    # if need_material_distance > 25:
                                                    #     continue
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or \
                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                        if bot_work_status.count(need_material_id) > 2:
                                                            continue
                                                        f.write('触发7.7\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(
                                                            station_material_list[second_need_id],
                                                            station_type_list[need_material_id])
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break
                                    # 所有4/5/6工作台都没有生产或有部分原料
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.3\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and \
                                                    station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏无
                                                if len(second_need_material_status) == 0:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # if need_material_distance > 25:
                                                        #     continue
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发7.8\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                if bot_work_status[robot_id] != -1:
                                    break

                        # 没有7需要材料，则去看4/5/6需不需要材料
                        if bot_work_status[robot_id] == -1:
                            for second_need_id, second_need_distance in sort_station_distance:
                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                if station_type_list[second_need_id] in [4, 5, 6]:
                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                    # 材料栏有原料且不满
                                    if len(second_need_material_status) != 0 and len(second_need_material_status) != 2:
                                        for need_material_id, need_material_distance in sort_station_distance:
                                            # if need_material_distance > 25:
                                            #     continue
                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                    (station_production_list[need_material_id] == 1 or \
                                                     0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                                if bot_work_status.count(need_material_id) > 2:
                                                    continue
                                                f.write('触发7.9\n')
                                                bot_work_status[robot_id] = need_material_id
                                                bot_goods_status[robot_id] = second_need_id
                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                station_material_list[second_need_id] = change_bit(
                                                    station_material_list[second_need_id],
                                                    station_type_list[need_material_id])
                                                break
                                if bot_work_status[robot_id] != -1:
                                    break
                            # 所有4/5/6工作台都没有生产或有部分原料
                            if bot_work_status[robot_id] == -1:
                                # f.write('触发9.2.3\n')
                                for second_need_id, second_need_distance in sort_station_distance:
                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                    if station_type_list[second_need_id] in [4, 5, 6]:
                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                        # 材料栏无
                                        if len(second_need_material_status) == 0:
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                # if need_material_distance > 25:
                                                #     continue
                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                                    if bot_work_status.count(need_material_id) > 2:
                                                        continue
                                                    f.write('触发7.10\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = second_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                    break
                                    if bot_work_status[robot_id] != -1:
                                        break

                    # 没有7号工作台
                    else:
                        for saven_need_id, saven_need_distance in sort_station_distance:
                            saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                            # f.write('触发9.2.1\n')
                            for need_material_id, need_material_distance in sort_station_distance:
                                if need_material_distance > 25:
                                    continue
                                # f.write('触发9.2.1.1\n')
                                # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                if station_type_list[need_material_id] in [4, 5, 6] and \
                                        station_type_list[need_material_id] not in saven_need_material_status and \
                                        (station_production_list[need_material_id] == 1 or \
                                         0 < station_process_list[need_material_id] < arrival_time(
                                                    need_material_distance)):
                                    if (need_material_id in bot_work_status and bot_goods_type[bot_work_status.index(need_material_id)] == station_type_list[need_material_id]) or \
                                            (need_material_id in bot_goods_status and bot_goods_type[bot_goods_status.index(need_material_id)] == station_type_list[need_material_id]):
                                        continue
                                    f.write('触发7.6\n')
                                    bot_work_status[robot_id] = need_material_id
                                    bot_goods_status[robot_id] = saven_need_id
                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                    station_material_list[saven_need_id] = change_bit(
                                        station_material_list[saven_need_id],
                                        station_type_list[need_material_id])
                                    break

                            # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                            if bot_work_status[robot_id] == -1:
                                # f.write('触发9.2.2\n')
                                for second_need_id, second_need_distance in sort_station_distance:
                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                    if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                        # 材料栏有原料且不满
                                        if len(second_need_material_status) != 0 and len(second_need_material_status) != 2:
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                if need_material_distance > 25:
                                                    continue
                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or \
                                                         0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                    if (need_material_id in bot_work_status and bot_goods_type[bot_work_status.index(need_material_id)] == station_type_list[need_material_id]) or \
                                                            (need_material_id in bot_goods_status and bot_goods_type[bot_goods_status.index(need_material_id)] == station_type_list[
                                                                need_material_id]):
                                                        continue
                                                    f.write('触发7.7\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = second_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[second_need_id] = change_bit(
                                                        station_material_list[second_need_id],
                                                        station_type_list[need_material_id])
                                                    break
                                    if bot_work_status[robot_id] != -1:
                                        break
                                # 所有4/5/6工作台都没有生产或有部分原料
                                if bot_work_status[robot_id] == -1:
                                    # f.write('触发9.2.3\n')
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6] and \
                                                station_type_list[second_need_id] not in saven_need_material_status:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏无
                                            if len(second_need_material_status) == 0:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    if need_material_distance > 25:
                                                        continue
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                        if (need_material_id in bot_work_status and bot_goods_type[bot_work_status.index(need_material_id)] == station_type_list[
                                                            need_material_id]) or \
                                                                (need_material_id in bot_goods_status and bot_goods_type[bot_goods_status.index(need_material_id)] == station_type_list[
                                                                    need_material_id]):
                                                            continue
                                                        f.write('触发7.8\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break
                            if bot_work_status[robot_id] != -1:
                                break

                    if bot_work_status[robot_id] == -1:
                        f.write('触发8.1\n')
                        # 循环找到7号工作台且有材料在原料栏但差材料的
                        for saven_need_id, saven_need_distance in sort_station_distance:
                            # if saven_need_distance > 25:
                            #     continue
                            if station_type_list[saven_need_id] == 7:
                                saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                # 判断有无7号物品,且不在其他机器人目标内
                                # if (station_production_list[saven_need_id] == 1 or 0 < station_process_list[saven_need_id] < arrival_time(saven_need_distance)) and \
                                #         not (saven_need_id in bot_work_status and bot_goods_type[bot_work_status.index(saven_need_id)] == 7):
                                #     f.write('触发8.2\n')
                                #     # todo 可能需要加一个判断是否有原料空缺，有的话携带原料过去，节省时间
                                #
                                #     bot_work_status[robot_id] = saven_need_id
                                #     bot_goods_status[robot_id] = -1
                                #     bot_goods_type[robot_id] = 7
                                #     break
                                # 材料栏有原料且不满
                                if len(saven_need_material_status) != 0 and len(saven_need_material_status) != 3:
                                    # f.write('触发9.1.2\n')
                                    for need_material_id, need_material_distance in sort_station_distance:
                                        # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间,且不在目标内
                                        if station_type_list[need_material_id] in [4, 5, 6] and station_type_list[need_material_id] not in saven_need_material_status and \
                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):

                                            if need_material_id in bot_work_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif need_material_id in bot_goods_status:
                                                is_repeat = False
                                                for i in range(4):
                                                    if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                        is_repeat = True
                                                        break
                                                if is_repeat:
                                                    continue
                                            elif bot_work_status.count(need_material_id) > 2:
                                                continue
                                            f.write('触发8.3\n')
                                            # f.write('触发9.1.3\n')
                                            bot_work_status[robot_id] = need_material_id
                                            bot_goods_status[robot_id] = saven_need_id
                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                            station_material_list[saven_need_id] = change_bit(
                                                station_material_list[saven_need_id],
                                                station_type_list[need_material_id])
                                            break

                                    # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                    if bot_work_status[robot_id] == -1:
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏有原料且不满
                                                if len(second_need_material_status) != 0 and len(second_need_material_status) != 2:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or \
                                                                 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发8.4\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(
                                                                station_material_list[second_need_id],
                                                                station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                        # 所有4/5/6工作台都没有生产或有部分原料
                                        if bot_work_status[robot_id] == -1:
                                            for second_need_id, second_need_distance in sort_station_distance:
                                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                                if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                    # 材料栏有原料且不满
                                                    if len(second_need_material_status) == 0:
                                                        for need_material_id, need_material_distance in sort_station_distance:
                                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                                    (station_production_list[need_material_id] == 1 or \
                                                                     0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                                if bot_work_status.count(need_material_id) > 2:
                                                                    continue
                                                                f.write('触发8.5\n')
                                                                bot_work_status[robot_id] = need_material_id
                                                                bot_goods_status[robot_id] = second_need_id
                                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                                station_material_list[second_need_id] = change_bit(
                                                                    station_material_list[second_need_id],
                                                                    station_type_list[need_material_id])
                                                                break
                                                if bot_work_status[robot_id] != -1:
                                                    break
                            if bot_work_status[robot_id] != -1:
                                break
                        # 没有原材料的情况下
                        if bot_work_status[robot_id] == -1:
                            for saven_need_id, saven_need_distance in sort_station_distance:
                                if station_type_list[saven_need_id] != 7:
                                    continue
                                saven_need_material_status = find_position_of_ones(station_material_list[saven_need_id])
                                # f.write('触发9.2.1\n')
                                for need_material_id, need_material_distance in sort_station_distance:
                                    # f.write('触发9.2.1.1\n')
                                    # 判断456哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                    if station_type_list[need_material_id] in [4, 5, 6] and \
                                            station_type_list[need_material_id] not in saven_need_material_status and \
                                            (station_production_list[need_material_id] == 1 or \
                                             0 < station_process_list[need_material_id] < arrival_time(
                                                        need_material_distance)):

                                        if need_material_id in bot_work_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_work_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif need_material_id in bot_goods_status:
                                            is_repeat = False
                                            for i in range(4):
                                                if bot_goods_type[i] == station_type_list[need_material_id] and need_material_id == bot_goods_status[i]:
                                                    is_repeat = True
                                                    break
                                            if is_repeat:
                                                continue
                                        elif bot_work_status.count(need_material_id) > 2:
                                            continue
                                        f.write('触发8.6\n')
                                        bot_work_status[robot_id] = need_material_id
                                        bot_goods_status[robot_id] = saven_need_id
                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                        station_material_list[saven_need_id] = change_bit(
                                            station_material_list[saven_need_id],
                                            station_type_list[need_material_id])
                                        break

                                # 如果没有找到符合要求的4/5/6，也就是没有该产品且没有该产品在生产,需要根据4/5/6情况去找1/2/3工作台
                                if bot_work_status[robot_id] == -1:
                                    # f.write('触发9.2.2\n')
                                    for second_need_id, second_need_distance in sort_station_distance:
                                        # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                        if station_type_list[second_need_id] in [4, 5, 6] and station_type_list[second_need_id] not in saven_need_material_status:
                                            second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                            # 材料栏有原料且不满
                                            if len(second_need_material_status) != 0 and len(second_need_material_status) != 2:
                                                for need_material_id, need_material_distance in sort_station_distance:
                                                    # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                    if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                        (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                        (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                            station_type_list[need_material_id] not in second_need_material_status and \
                                                            (station_production_list[need_material_id] == 1 or \
                                                             0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                        if bot_work_status.count(need_material_id) > 2:
                                                            continue
                                                        f.write('触发8.7\n')
                                                        bot_work_status[robot_id] = need_material_id
                                                        bot_goods_status[robot_id] = second_need_id
                                                        bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                        station_material_list[second_need_id] = change_bit(
                                                            station_material_list[second_need_id],
                                                            station_type_list[need_material_id])
                                                        break
                                        if bot_work_status[robot_id] != -1:
                                            break
                                    # 所有4/5/6工作台都没有生产或有部分原料
                                    if bot_work_status[robot_id] == -1:
                                        # f.write('触发9.2.3\n')
                                        for second_need_id, second_need_distance in sort_station_distance:
                                            # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                            if station_type_list[second_need_id] in [4, 5, 6] and \
                                                    station_type_list[second_need_id] not in saven_need_material_status:
                                                second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                                # 材料栏无
                                                if len(second_need_material_status) == 0:
                                                    for need_material_id, need_material_distance in sort_station_distance:
                                                        # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                        if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                            (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                            (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                                station_type_list[need_material_id] not in second_need_material_status and \
                                                                (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                            if bot_work_status.count(need_material_id) > 2:
                                                                continue
                                                            f.write('触发8.8\n')
                                                            bot_work_status[robot_id] = need_material_id
                                                            bot_goods_status[robot_id] = second_need_id
                                                            bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                            station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                            break
                                            if bot_work_status[robot_id] != -1:
                                                break
                                if bot_work_status[robot_id] != -1:
                                    break

                        # 没有7需要材料，则去看4/5/6需不需要材料
                        if bot_work_status[robot_id] == -1:
                            for second_need_id, second_need_distance in sort_station_distance:
                                # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                if station_type_list[second_need_id] in [4, 5, 6]:
                                    second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                    # 材料栏有原料且不满
                                    if len(second_need_material_status) != 0 and len(second_need_material_status) != 2:
                                        for need_material_id, need_material_distance in sort_station_distance:
                                            # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                            if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                    station_type_list[need_material_id] not in second_need_material_status and \
                                                    (station_production_list[need_material_id] == 1 or \
                                                     0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                if bot_work_status.count(need_material_id) > 2:
                                                    continue
                                                f.write('触发8.9\n')
                                                bot_work_status[robot_id] = need_material_id
                                                bot_goods_status[robot_id] = second_need_id
                                                bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                station_material_list[second_need_id] = change_bit(
                                                    station_material_list[second_need_id],
                                                    station_type_list[need_material_id])
                                                break
                                if bot_work_status[robot_id] != -1:
                                    break
                            # 所有4/5/6工作台都没有生产或有部分原料
                            if bot_work_status[robot_id] == -1:
                                # f.write('触发9.2.3\n')
                                for second_need_id, second_need_distance in sort_station_distance:
                                    # 排除4/5/6之外的工作台,且4/5/6不在7号工作台目标内
                                    if station_type_list[second_need_id] in [4, 5, 6]:
                                        second_need_material_status = find_position_of_ones(station_material_list[second_need_id])
                                        # 材料栏无
                                        if len(second_need_material_status) == 0:
                                            for need_material_id, need_material_distance in sort_station_distance:
                                                # 判断1/2/3哪一种不在原料区，且有产品可以获取或到达时间大于生产时间
                                                if ((station_type_list[need_material_id] in [1, 2] and station_type_list[second_need_id] == 4) or
                                                    (station_type_list[need_material_id] in [1, 3] and station_type_list[second_need_id] == 5) or
                                                    (station_type_list[need_material_id] in [2, 3] and station_type_list[second_need_id] == 6)) and \
                                                        station_type_list[need_material_id] not in second_need_material_status and \
                                                        (station_production_list[need_material_id] == 1 or 0 < station_process_list[need_material_id] < arrival_time(need_material_distance)):
                                                    if bot_work_status.count(need_material_id) > 2:
                                                        continue
                                                    f.write('触发8.10\n')
                                                    bot_work_status[robot_id] = need_material_id
                                                    bot_goods_status[robot_id] = second_need_id
                                                    bot_goods_type[robot_id] = station_type_list[need_material_id]
                                                    station_material_list[second_need_id] = change_bit(station_material_list[second_need_id], station_type_list[need_material_id])
                                                    break
                                    if bot_work_status[robot_id] != -1:
                                        break



            # 根据有无货物定义机器人半径
            if bot_type_list[robot_id] != 0:
                bot_radius_list[robot_id] = 0.53
            else:
                bot_radius_list[robot_id] = 0.45

            bot_target_location[robot_id] = np.array(station_location_list[bot_work_status[robot_id]])

        # todo 断下一时刻是否会碰撞,会的话改变方向
        # f.write('当前机器人位置：%s，朝向：%s，速度：%s，半径：%s，目标：%s\n' % (
        #     str(bot_location_list), str(bot_direction_list), str(bot_line_speed_list), str(bot_radius_list),
        #     str(bot_target_location)))
        avoid_collisions(robots, bot_location_list, station_location_list, bot_direction_list, bot_work_status)

        finish()  # 一帧操作结束，以OK结束
        f.write('\n')
    f.close()  # 关闭文件写入
